# #!/bin/bash

# output_file="output/results.txt"

# # 清空结果文件
# > "$output_file"

# # 编译和运行每个版本
# for optimization in "" "-O1" "-O2"; do
#   echo "Compiling with optimization level: $optimization" >> "$output_file"
  
#   g++ main.cpp train.cpp guessing.cpp md5.cpp -o test.exe $optimization
  
#   if [ $? -eq 0 ]; then
#     echo "Running test.exe with optimization level: $optimization" >> "$output_file"
#     ./test.exe >> "$output_file"
#     echo "----------------------------------------" >> "$output_file"
#   else
#     echo "Compilation failed for optimization level: $optimization" >> "$output_file"
#   fi
# done

#!/bin/bash

output_file="output/results.txt"

# 清空结果文件
> "$output_file"

# 编译和运行每个版本
for optimization2 in "" "-O1" "-O2"; do
  for optimization in "" "-O1" "-O2"; do
    echo "Compiling with optimization level: $optimization" >> "$output_file"
    echo "Compiling GPU code with optimization level: $optimization2" >> "$output_file"
    
    nvcc -c gpu.cu -o gpu.o $optimization2
    g++ main.cpp train.cpp guessing.cpp md5.cpp gpu.o -o test.exe -lcudart $optimization
    
    if [ $? -eq 0 ]; then
      echo "Running test.exe with optimization level: $optimization" >> "$output_file"
      echo "Running GPU code with optimization level: $optimization2" >> "$output_file"
      nvprof ./test.exe >> "$output_file" 2>&1
      echo "----------------------------------------" >> "$output_file"
    else
      echo "Compilation failed for optimization level: $optimization" >> "$output_file"
    fi
  done
done